import java.util.*;

class Solution {
    public List<Integer> findSubstring(String s, String[] words) {
        HashMap<String ,Integer> hash1=new LinkedHashMap<>();
        List<Integer> list=new ArrayList<>();
        int len=words[0].length();
        int m=words.length;
        for (int i = 0; i < words.length; i+=len) {
            String str=words[i].substring(i,i+len);
            hash1.put(str,hash1.getOrDefault(str,0)+1);
        }
        for (int i = 0; i <len ; i++) {
            int count = 0;
            HashMap<String, Integer> hash2 = new LinkedHashMap<>();
            for (int right = i, left = 0; right + len <= s.length(); right++) {
                String in = s.substring(right, right + len);
                hash2.put(in, hash2.getOrDefault(in, 0) + 1);
                if (hash2.get(in) <= hash1.getOrDefault(in, 0)) {
                    count++;
                }

                if (right - left + 1 > m * len) {
                    String out = s.substring(left, left + len);
                    if (hash2.get(in) <= hash1.getOrDefault(in, 0)) {
                        count--;
                    }
                    hash2.put(out, hash2.get(out) - 1);
                    left += 3;
                }
                if (count == m) {
                    list.add(left);
                }


            }
        }
return list;


    }
}